Imports System.Data.SqlClient
Imports AppsUtility.EncDec
Imports System.Configuration

Public Class frmGLTransEnquiry

    Inherits System.Windows.Forms.Form
    Dim util As New AppsUtility.EncDec
    Public strCon As String = util.toDecrypt(ConfigurationManager.AppSettings("SQLString")).Replace("serps", CurrentDB)
    Dim sqlCon As SqlConnection = New SqlConnection(strCon)
    Dim strsql As String
    Dim sqlCmd As SqlCommand = New SqlCommand(strsql, sqlCon)
    Dim rdr As SqlDataReader
    Dim FrDt, ToDt As String
    Dim OldTodate, OldFrdate As String
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmdRefresh As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents dgDocEnq As System.Windows.Forms.DataGrid
    Friend WithEvents tbTrxNo As System.Windows.Forms.TextBox
    Friend WithEvents tbDate As System.Windows.Forms.TextBox
    Friend WithEvents tbSource As System.Windows.Forms.TextBox
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents gLlistOfTransEnquiry1 As GLlistOfTransEnquiry
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.tbTrxNo = New System.Windows.Forms.TextBox()
        Me.tbDate = New System.Windows.Forms.TextBox()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.tbSource = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.dgDocEnq = New System.Windows.Forms.DataGrid()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.gLlistOfTransEnquiry1 = New GLlistOfTransEnquiry()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdRefresh = New DevComponents.DotNetBar.ButtonX()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        CType(Me.dgDocEnq, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(7, 11)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(84, 18)
        Me.Label1.TabIndex = 47
        Me.Label1.Text = "Trx. Number"
        '
        'tbTrxNo
        '
        Me.tbTrxNo.BackColor = System.Drawing.Color.White
        Me.tbTrxNo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbTrxNo.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbTrxNo.Location = New System.Drawing.Point(10, 56)
        Me.tbTrxNo.MaxLength = 8
        Me.tbTrxNo.Name = "tbTrxNo"
        Me.tbTrxNo.Size = New System.Drawing.Size(131, 26)
        Me.tbTrxNo.TabIndex = 48
        '
        'tbDate
        '
        Me.tbDate.BackColor = System.Drawing.Color.White
        Me.tbDate.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDate.Location = New System.Drawing.Point(526, 56)
        Me.tbDate.Name = "tbDate"
        Me.tbDate.ReadOnly = True
        Me.tbDate.Size = New System.Drawing.Size(120, 26)
        Me.tbDate.TabIndex = 94
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.BackColor = System.Drawing.Color.Transparent
        Me.Label8.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label8.Location = New System.Drawing.Point(521, 11)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(37, 18)
        Me.Label8.TabIndex = 93
        Me.Label8.Text = "Date"
        '
        'tbSource
        '
        Me.tbSource.BackColor = System.Drawing.Color.White
        Me.tbSource.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbSource.Location = New System.Drawing.Point(652, 56)
        Me.tbSource.Name = "tbSource"
        Me.tbSource.ReadOnly = True
        Me.tbSource.Size = New System.Drawing.Size(113, 26)
        Me.tbSource.TabIndex = 97
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(650, 11)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(52, 18)
        Me.Label2.TabIndex = 96
        Me.Label2.Text = "Refer #"
        '
        'dgDocEnq
        '
        Me.dgDocEnq.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgDocEnq.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgDocEnq.CaptionVisible = False
        Me.dgDocEnq.DataMember = ""
        Me.dgDocEnq.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgDocEnq.Location = New System.Drawing.Point(10, 86)
        Me.dgDocEnq.Name = "dgDocEnq"
        Me.dgDocEnq.PreferredColumnWidth = 175
        Me.dgDocEnq.ReadOnly = True
        Me.dgDocEnq.Size = New System.Drawing.Size(755, 251)
        Me.dgDocEnq.TabIndex = 103
        Me.dgDocEnq.TabStop = False
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmdRefresh)
        Me.GroupPanel1.Controls.Add(Me.cmdPrint)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.Label8)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(779, 395)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 104
        Me.GroupPanel1.Text = "GL Transaction - Enquiry"
        '
        'cmdRefresh
        '
        Me.cmdRefresh.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRefresh.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRefresh.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRefresh.Location = New System.Drawing.Point(591, 330)
        Me.cmdRefresh.Name = "cmdRefresh"
        Me.cmdRefresh.Size = New System.Drawing.Size(82, 27)
        Me.cmdRefresh.TabIndex = 236
        Me.cmdRefresh.Text = "Refresh"
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(503, 330)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 27)
        Me.cmdPrint.TabIndex = 235
        Me.cmdPrint.Text = "Print"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(679, 330)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 234
        Me.cmdExit.Text = "Exit"
        '
        'frmGLTransEnquiry
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(779, 395)
        Me.ControlBox = False
        Me.Controls.Add(Me.dgDocEnq)
        Me.Controls.Add(Me.tbSource)
        Me.Controls.Add(Me.tbDate)
        Me.Controls.Add(Me.tbTrxNo)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Location = New System.Drawing.Point(30, 70)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmGLTransEnquiry"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgDocEnq, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private Sub dgDocEnq_load()
        Try
            tbTrxNo.Text = tbTrxNo.Text.Trim
            strsql = "select AcNum,AcCent,AccountName,trxdate TrxDate,trxsource TrxSource," & _
            "trxrefer TrxRefer,trxamt DrAmount,null CrAmount," & _
            "TrxNumber TrxNumber  from GLTRX A,ACCOUNT B where " & _
            "a.AcNum=b.AccountNumber and " & _
            "TrxNumber='" & tbTrxNo.Text & "'  and TrxAmt>0  " & _
            "UNION ALL " & _
            "select AcNum,AcCent,AccountName,trxdate TrxDate,trxsource TrxSource,trxrefer TrxRefer," & _
            "null DrAmount,abs(trxamt) CrAmount,TrxNumber TrxNumber from " & _
            "GLTRX A,ACCOUNT B  where " & _
            "a.AcNum=b.AccountNumber and " & _
            "TrxNumber='" & tbTrxNo.Text & "'  " & _
            "and TrxAmt<0 " & _
            " order by trxdate "

            Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
            Dim ds As New DataSet("DOCENQ")
            da.Fill(ds, "DOCENQ")
            If ds.Tables(0).Rows.Count > 0 Then
                tbDate.Text = ds.Tables(0).Rows(0).Item("TrxDate")
                tbSource.Text = ds.Tables(0).Rows(0).Item("TrxSource")
                dgDocEnq.DataSource = ds
                dgDocEnq.DataMember = "DOCENQ"
                dgDocEnq.ReadOnly = True
                dgDocEnq.TableStyles.Clear()
                dgDocEnq_Style()
            Else
                MsgBox("Transaction NOT found!", MsgBoxStyle.Exclamation, "Inventory Manager")
                tbTrxNo.Focus()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub dgDocEnq_Style()
        With dgDocEnq
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With

        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .MappingName = "DOCENQ"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With


        Dim cs As DataGridColumnStyle
        cs = New DataGridTextBoxColumn
        cs.Width = 75
        cs.MappingName = "AcNum"
        cs.HeaderText = "Account"
        cs.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs)

        Dim cs0 As DataGridColumnStyle
        cs0 = New DataGridTextBoxColumn
        cs0.Width = 60
        cs0.MappingName = "AcCent"
        cs0.HeaderText = "Dpt"
        cs0.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs0)

        Dim cs01 As DataGridColumnStyle
        cs01 = New DataGridTextBoxColumn
        cs01.Width = 203
        cs01.MappingName = "AccountName"
        cs01.HeaderText = "Account Name"
        cs01.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs01)

        Dim cs3 As DataGridColumnStyle
        cs3 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs3.Width = 102
        cs3.MappingName = "DrAmount"
        cs3.HeaderText = "Debit Amount "
        cs3.NullText = ""
        cs3.ReadOnly = True
        cs3.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs3)

        Dim cs4 As DataGridColumnStyle
        cs4 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs4.Width = 102
        cs4.MappingName = "CrAmount"
        cs4.HeaderText = "Credit Amount "
        cs4.NullText = ""
        cs4.ReadOnly = True
        cs4.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs4)

        Dim cs5 As DataGridColumnStyle
        cs5 = New DataGridTextBoxColumn  ' Add the standard column style.
        cs5.Width = 171
        cs5.MappingName = "TrxRefer"
        cs5.HeaderText = "Description"
        cs5.NullText = ""
        cs5.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs5)
        dgDocEnq.TableStyles.Add(grdTableStyle)

    End Sub

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            dgDocEnq_load()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub
    Private Sub tbTrxNo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbTrxNo.KeyUp
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        Me.Cursor = Cursors.WaitCursor
        Try
            Dim ds As DataSet = New DataSet("JisRpt")
            Dim table As DataTable = New DataTable("JisRpt")
            table.Columns.Add("Str1")
            table.Columns.Add("Str2")
            table.Columns.Add("Str3")
            table.Columns.Add("Str4")
            table.Columns.Add("Dec1")
            table.Columns.Add("Dec2")

            Dim mrow As Integer
            Dim cm As CurrencyManager = BindingContext(dgDocEnq.DataSource, dgDocEnq.DataMember)
            Dim dv As DataView = cm.List
            dv.RowStateFilter = DataViewRowState.CurrentRows
            mrow = dv.Count
            Dim n As Integer
            For n = 0 To mrow - 1
                Dim nrow As DataRow = table.NewRow()
                nrow("Str1") = dgDocEnq(n, 0) + "-" + dgDocEnq(n, 1)
                nrow("Str2") = dgDocEnq(n, 2)
                nrow("Str3") = dgDocEnq(n, 5)
                nrow("Dec1") = dgDocEnq(n, 3)
                nrow("Dec2") = dgDocEnq(n, 4)
                table.Rows.Add(nrow)
            Next
            ds.Tables.Add(table)
            gLlistOfTransEnquiry1.Load()
            gLlistOfTransEnquiry1.SetDataSource(ds)

            gLlistOfTransEnquiry1.SetParameterValue("CompanyName", CompanyTitle)
            gLlistOfTransEnquiry1.SetParameterValue("ReportName", "TRANSACTIONS ENQUIRY:TRX.NO.:" + tbTrxNo.Text)
            gLlistOfTransEnquiry1.SetParameterValue("ReportCriteria", "TRX.DATE:" + tbDate.Text + " REFER #:" + tbSource.Text)

            If PrntPrv Is Nothing Then
                PrntPrv = New PrintPreviewForm
                PrntPrv.CrRptView.ReportSource = gLlistOfTransEnquiry1
                PrntPrv.ShowDialog()
            End If

            'gLlistOfTransEnquiry1.PrintToPrinter(1, True, 0, 0)
            gLlistOfTransEnquiry1.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Me.Cursor = Cursors.Default
    End Sub
    Private Sub dgDocEnq_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgDocEnq.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgDocEnq.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgDocEnq.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgDocEnq.Select(hti.Row)
        End If
    End Sub

    Private Sub GLtransEnquiry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub dgDocEnq_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles dgDocEnq.Navigate

    End Sub
End Class
